package org.jeecg.modules.oms.parser;

import org.jeecg.modules.oms.parser.impl.confirmation.XinGeErWindowDoorDispatcher;
import org.jeecg.modules.oms.parser.impl.confirmation.ChangFengWindowConfirmationFileParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 窗型确认文件解析器工厂
 * 根据优化软件类型返回对应的解析器
 */
@Component
public class WindowConfirmationFileParserFactory {

    private static final Map<Integer, WindowConfirmationFileParser> PARSER_MAP = new HashMap<>();

    /**
     * 优化软件类型：长风
     */
    public static final int OPTIMIZE_SOFTWARE_TYPE_CHANGFENG = 0;

    /**
     * 优化软件类型：新格尔
     */
    public static final int OPTIMIZE_SOFTWARE_TYPE_XINGEER = 1;

    @Autowired
    public WindowConfirmationFileParserFactory(
            ChangFengWindowConfirmationFileParser changFengParser,
            XinGeErWindowDoorDispatcher xinGeErDispatcher) {
        PARSER_MAP.put(OPTIMIZE_SOFTWARE_TYPE_CHANGFENG, changFengParser);
        PARSER_MAP.put(OPTIMIZE_SOFTWARE_TYPE_XINGEER, xinGeErDispatcher);
    }

    /**
     * 根据优化软件类型获取对应的解析器
     *
     * @param optimizeSoftwareType 优化软件类型
     * @return 窗型确认文件解析器
     * @throws IllegalArgumentException 如果没有找到对应的解析器
     */
    public static WindowConfirmationFileParser getParser(Integer optimizeSoftwareType) {
        WindowConfirmationFileParser parser = PARSER_MAP.get(optimizeSoftwareType);
        if (parser == null) {
            // 默认使用长风解析器
            parser = PARSER_MAP.get(OPTIMIZE_SOFTWARE_TYPE_CHANGFENG);
            if (parser == null) {
                throw new IllegalArgumentException("未找到对应的窗型确认文件解析器");
            }
        }
        return parser;
    }
} 